package com.gl.db.dataSource;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

import org.apache.commons.dbcp.BasicDataSource;

import com.gl.util.property.PropertyRead1;

public class DBSourceTest {

public static BasicDataSource ds = null;
	
	public static void initDBSource(String paramFile) throws Exception{
		ds = new BasicDataSource();
		Properties props = new Properties();
		props.load(new FileInputStream(paramFile));
		ds.setDriverClassName(props.getProperty("driver"));
		ds.setUrl(props.getProperty("url"));
		ds.setUsername(props.getProperty("user"));
		ds.setPassword(props.getProperty("pass"));
		ds.setInitialSize(5);
		ds.setMaxActive(25);
		ds.setMinIdle(2);
	}
	
	public void execSql(String sql) throws Exception{
		Connection conn = ds.getConnection();
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery(sql);
		while(rs.next()){
			System.out.println("name:" + rs.getString("name"));
		}
		conn.close();
	}
	public static void main(String[] args) throws Exception{
		PropertyRead1 pr = new PropertyRead1();
		pr.initParam("src/mysql.properties");
		pr.execSql("select * from course");
		
	}
}
